package com.jt9003.controller;

import com.jt9003.pojo.Patient;
import com.jt9003.pojo.PatientNamber;
import com.jt9003.pojo.Register;
import com.jt9003.pojo.User1;
import com.jt9003.service.TestService;
import com.jt9003.service.impl.P_RegistrationServiceimpl;
import com.jt9003.service.impl.TestServiceimpl;
import com.jt9003.utils.P_NamberUtil;
import com.jt9003.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;


@RestController
public class TestController {

    //获取Service层对象
    @Autowired
    TestServiceimpl ts;

    @Autowired
    P_RegistrationServiceimpl pr;

    @Resource
    RedisUtil redisUtil;

   /* @RequestMapping("/test")
    public String Test(Integer id){
        Patient s=ts.SelectTest(id);
        return "返回数据"+s.getpName();
    }*/

    /*@RequestMapping("Test")
   public String Test(Register register){
        System.out.println("控制层获取数据========================"+register);
       int a = pr.test(register);
    return  "返回数据是"+a;
   }*/

   /* @RequestMapping("/testRedis")
    public String testRedis(){

        User1 user1=(User1)redisUtil.get("LoggedInUsers");

        String name =user1.getuName();

        return name;
    }*/

    //设置接诊人数
    @RequestMapping("/testSetDate")
    public boolean setPatientsNamber() throws ParseException {
        boolean check = true;
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date start = sdf.parse(P_NamberUtil.am1);
        Date end = sdf.parse(P_NamberUtil.am2);
        check=belongCalendar(now,start,end);
        if (check==false){
            Date start2 = sdf.parse(P_NamberUtil.pm1);
            Date end2 = sdf.parse(P_NamberUtil.pm2);
            check=belongCalendar(now,start2,end2);
        }
        if (check==false){
            Date start3 = sdf.parse(P_NamberUtil.night1);
            Date end3 = sdf.parse(P_NamberUtil.night2);
            check=belongCalendar(now,start3,end3);
        }
        return check;
    }


    public boolean belongCalendar(Date nowTime, Date beginTime, Date endTime) {
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);
        Calendar begin = Calendar.getInstance();
        begin.setTime(beginTime);
        Calendar end = Calendar.getInstance();
        end.setTime(endTime);
        if (date.after(begin) && date.before(end)) {
            return true;
        } else if (nowTime.compareTo(beginTime) == 0 || nowTime.compareTo(endTime) == 0) {
            return true;
        } else {
            return false;
        }
    }

}
